package com.liuguang.framework.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import com.liuguang.framework.utils.AppUtils;
import java.util.LinkedList;

public class BaseApplication extends Application {
    private static Context context;
    public LinkedList<Activity> activitys = new LinkedList<>();

    public void onCreate() {
        super.onCreate();
        context =  getApplicationContext() ;
        AppUtils.init(this);
    }

    public static Context getContext() {
        return context;
    }

    public void addActivity(Activity activity) {
        this.activitys.add(0, activity);
    }

    public void removeActivity(Activity activity) {
        if (activity != null) {
            this.activitys.remove(activity);
        }
    }

    public Activity getTopActivity() {
        return (Activity) this.activitys.getFirst();
    }

    public void exit() {
        while (this.activitys.size() != 0) {
            Activity activity = (Activity) this.activitys.poll();
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
    }
}
